/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOS.DAOSAUTORES;

import Entidades.EntidadesAutores.Tesis;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author LUIGI
 */
@Stateless
@LocalBean
public class TesisDAO {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    @PersistenceContext
    EntityManager em;
    public void crear(Tesis t) {
        em.persist(t);
    }

    public void actualizar(Tesis t) {
        em.merge(t);
    }

    public void borrar(Integer id) {
        Tesis tes = em.find(Tesis.class, id);
        em.remove(tes);
    }

    public void guardar(Tesis t) {
        if (t.getIdTesis() == null) {
            crear(t);
        } else {
            actualizar(t);
        }
    }

    public List<Tesis> BuscarTodosTesis() {
        return em.createNamedQuery("Tesis.findAll", Tesis.class).getResultList();
    }

    public List<Tesis> BuscarTesis(String cadena) {
        return em.createNamedQuery("Tesis.findByIdTesis", Tesis.class)
                .setParameter("tesis", cadena).getResultList();
    }
    
}
